package com.dissertation.respository;

import com.dissertation.model.CategoryLeaf;
import com.dissertation.model.CategoryTree;
import com.dissertation.model.auth.Role;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import java.util.List;

public interface CategoryTreeRepository extends MongoRepository<CategoryTree, String> {


    CategoryTree findByUniqueName(String uniqueName);

    @Query("{" +
            "        role:{" +
            "                $elemMatch:{name:?0}" +
            "            }," +
            "         'categoryLeaves.role':{" +
            "                $elemMatch:{name:?0}" +
            "             }" +
            "    }")
    List<CategoryTree> findAllByRoleIs(String roleName);



}
